package com.dong.module.menulog.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dong.common.annotation.RequestMapping;
import com.dong.common.pojo.ResultVO;
import com.dong.module.foodmenu.pojo.FoodMenu;
import com.dong.module.menulog.pojo.MenuLog;
import com.dong.module.menulog.service.MenuLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: 陈瑞东
 * @create: 2021-08-25 11:14
 */
@Controller
@RequestMapping("log")
public class MenuLogController{

    @Autowired
    private MenuLogService menuLogService;

    @RequestMapping("count")
    public ResultVO<Integer> count(String foodId) {
        int data = 0;
        try {
            data = menuLogService.countLog(foodId);
        } catch (Exception e) {
            return ResultVO.fail(e.getMessage());
        }
        return ResultVO.success(data);
    }

    @RequestMapping("save")
    public ResultVO<Void> count(String id, String foodId, String description, String filename) {
        try {
            menuLogService.save(id, foodId, description, filename);
        } catch (Exception e) {
            return ResultVO.fail(e.getMessage());
        }
        return ResultVO.success(null);
    }

    @RequestMapping("getByCount")
    public ResultVO<MenuLog> getByCount(String foodId, int count) {
        MenuLog data = new MenuLog();
        try {
            data = menuLogService.getOne(new QueryWrapper<MenuLog>().eq("food_id", foodId).eq("count", count));
        } catch (Exception e) {
            return ResultVO.fail(e.getMessage());
        }
        return ResultVO.success(data);
    }

    @RequestMapping("getById")
    public ResultVO<MenuLog> getByCount(String id) {
        MenuLog data = new MenuLog();
        try {
            data = menuLogService.getById(id);
        } catch (Exception e) {
            return ResultVO.fail(e.getMessage());
        }
        return ResultVO.success(data);
    }

}
